﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Philip Stears 
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@connectbasic.net.
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

namespace ConnectBasic.ObjectModel
{
    using ConnectBasic.Execution;
    using DlrExpression = Microsoft.Linq.Expressions.Expression;

    /// <summary>
    /// Represents a statement which invokes a method.
    /// </summary>
    public class InvokeStatement : StatementNodeBase
    {
        InvokeExpression mInvoke;

        /// <summary>
        /// Initializes an instance of the <see cref="InvokeStatement" /> class.
        /// </summary>
        /// <param name="invoke">The expression which defines the method to invoke.</param>
        public InvokeStatement(InvokeExpression invoke)
        {
            mInvoke = invoke;
        }

        /// <summary>
        /// Gets the expression which defines the method to invoke.
        /// </summary>
        public InvokeExpression Invoke
        {
            get { return mInvoke; }
        }

        /// <inheritdoc />
        public override DlrExpression Compile(BasicCodeGenerator gen)
        {
            return DlrExpression.Block(typeof(void), mInvoke.Compile(gen));
        }
    }
}
